package cn.com.anysdk.starter.config.oss;

import cn.com.anysdk.oss.api.IOssService;
import cn.com.anysdk.oss.config.LocalFileSystemConfig;
import cn.com.anysdk.oss.impl.LocalFileSystemService;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties(LocalFileSystemProperties.class)
@ConditionalOnProperty(prefix = "anysdk.oss.local", name = "base-path")
public class LocalFileSystemAutoConfiguration {

    @Bean
    public IOssService localFileSystemService(LocalFileSystemProperties properties) {
        LocalFileSystemConfig config = new LocalFileSystemConfig();
        config.setBasePath(properties.getBasePath());
        config.setPrivate(properties.isPrivate());
        config.setIntranet(properties.isIntranet());
        config.setCustomDomain(properties.getCustomDomain());
        return new LocalFileSystemService(config);
    }
}